﻿
@section scripts{
    <script type="text/javascript">
        var bootstrap = function ($, ibpm) {
            "use strict";
            var page = {
                init: function () {
                    $("#En_add").on('click', page.AddAct);
                    $("#En_edit").on('click', page.EditAct);
                    $("#En_delete").on('click', page.DelAct);
                    $("#En_config").on('click', page.configAct);
                    $("#Btn_Save").on('click', page.configSave);
                    $("#btn_Search").on('click', function () {
                        page.search();
                    });
                    $('#btn_Refresh').on('click', function () {
                        location.reload();
                    });
                    page.initGrid();
                    page.bind();
                },
                bind: function () {
                    
                },
                initGrid: function () {
                    $('#gridtable').jfGrid({
                        url: top.$.rootUrl + '/Org/Role/GetPageList',
                        headData: [
                            { label: '名称', name: 'FullName', index: "FullName", width: 160, align: 'left' },
                            { label: '编码', name: 'RoleCode', index: "RoleCode", width: 180, align: 'left' },
                            { label: '职务', name: 'PositionName', width: 160, align: 'center' },
                            {
                                label: "", name: "btn", width: 120, align: "right",
                                formatter: function (value, row, op, $cell) {
                                    return '';
                                }
                            },
                        ],
                        mainId: 'RoleId',
                        sidx: 'RoleCode',    //排序
                        isPage: true,
                        rows: 18,
                    }).jfGridSet('reload'); //默认带数据
                },
                AddAct: function () {
                    ibpm.httpAsyncPost(top.$.rootUrl + "/Org/Role/NodeAdd", {}, function (json) {
                        $("#NodeSave").ibpm_SetFormData(json.data);
                        $('#AddNode').modal("show");
                    });
                },
                EditAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('RoleId');
                    if (ibpm.checkrow(keyValue)) {
                        ibpm.postForm(top.$.rootUrl + "/Org/Role/NodeEdit", { keyValue: keyValue }, function (json) {
                            $("#NodeSave").ibpm_SetFormData(json.data);
                            $('#AddNode').modal("show");
                        });
                    }
                },
                DelAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('RoleId');
                    if (ibpm.checkrow(keyValue)) {
                        ibpm.layerConfirm('是否确认删除该项！', function (res) {
                            if (res) {
                                ibpm.deleteForm(top.$.rootUrl + '/Org/Role/NodeDelete', { keyValue: keyValue }, function () {
                                    page.search();
                                });
                            }
                        });
                    }
                },
                configAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('RoleId');
                    $('#using_tree').html('');
                    if (ibpm.checkrow(keyValue)) {
                        $('#using_tree').ibpm_tree({
                            url: top.$.rootUrl + '/Org/Role/GetTreeMenu',
                            isCheckbox: true,
                            hasSearch: true,
                            isLeaf: false,
                            multiple: true,
                            icons: true,
                            threeState: true,
                            nodeCheck: function (items, SelectNode) {
                                var nid = SelectNode.id;
                                var ntxt = SelectNode.text;
                                var nicon = SelectNode.icon;
                                if (nicon == "fa fa-bars") {
                                    $('#SelectModule').val(ntxt);
                                    $('#SelectModuleId').val(nid);
                                }
                                else {
                                    $('#SelectModule').val('');
                                    $('#SelectModuleId').val('');
                                }
                            }
                        });
                        setTimeout(function () {
                            var keyValue = $('#gridtable').jfGridValue('RoleId');
                            ibpm.httpAsyncGet(top.$.rootUrl + '/Org/Role/GetRoleModuleID?id=' + keyValue, function (res) {
                                $('#using_tree').ibpm_treeSet('setCheck', res.data);
                            });
                        }, 300);
                        $('#ConfigTree').modal("show");
                    }
                },
                configSave: function () {
                    //获取所有选中节点数据
                    var ls = $('#using_tree').ibpm_treeSet('getCheckNodes');
                    //提交保存
                    var keyValue = $('#gridtable').jfGridValue('RoleId');
                    var param = { EnId: keyValue };
                    param.ContentTxt = JSON.stringify(ls);

                    ibpm.httpAsyncPost(top.$.rootUrl + "/Org/Role/ConfigSave", param, function (json) {
                        $('#ConfigTree').modal("hide");
                        if (!!json.info)
                            ibpm.alert.success(json.info);
                    });
                },
                search: function (param) {
                    param = param || {};
                    param.keyword = $('#txt_Keyword').val();
                    $('#gridtable').jfGridSet('reload', param);
                }
            };
            page.init();
        };
        function EndReq(data) {
            $('#AddNode').modal("hide");
            $('#gridtable').jfGridSet('reload');
        };
    </script>
}

<div class="row">
    <div class="step-pane">
        <div class="row">
            <div class="col-md-5">
                <div class="input-group">
                    <input id="txt_Keyword" type="text" class="form-control-sm form-control" placeholder="请输入要查询的关键字" />
                    <span id="btn_Search" class="input-group-addon btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</span>
                    <span id="btn_Refresh" class="input-group-addon btn btn-info"><i class="fa fa-refresh"></i>&nbsp;刷新</span>
                </div>
            </div>
            <div class="col-md-7">
                <div class="btn-group btn-group-sm" style="float:right;">
                    <a id="En_config" class="btn btn-default"><i class="fa fa-pencil-square-o"></i>&nbsp;配置角色</a>
                    <a id="En_add" class="btn btn-default"><i class="fa fa-plus"></i>&nbsp;新增角色</a>
                    <a id="En_edit" class="btn btn-default"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑角色</a>
                    <a id="En_delete" class="btn btn-default"><i class="fa fa-trash-o"></i>&nbsp;删除角色</a>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="step-pane">
        <div id="gridtable" style="margin-top:10px;"></div>
    </div>
</div>

<div class="modal fade" id="AddNode" tabindex="-11" role="dialog" aria-labelledby="AddNode" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <h3 class="modal-title">角色基础信息</h3>
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
            </div>
            <form action="/Org/Role/NodeSave" id="NodeSave" method="post" onsubmit="return FormSaveReport('NodeSave');">
                <div class="modal-body">
                    <input type="hidden" id="RoleId" name="RoleId" value="" />
                    <input type="hidden" id="ModifyUserId" name="ModifyUserId" value="" />
                    <div class="row">
                        <div class="form-group col-sm-6">
                            <label>角色编码</label>
                            <input class="form-control single-line" id="RoleCode" name="RoleCode" type="text" readonly>
                        </div>
                        <div class="form-group col-sm-6">
                            <label>角色名称</label>
                            <input class="form-control single-line" id="FullName" name="FullName" placeholder="角色名称" type="text" value="">
                        </div>
                    </div>
                    <div class="block">
                        <div class="form-group">
                            <label>职务</label>
                            <input class="form-control single-line" id="PositionName" name="PositionName" placeholder="职务" type="text" value="">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
                    <input type="submit" value="Save" class="btn btn-success">
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="ConfigTree" tabindex="-22" role="dialog" aria-labelledby="ConfigTree" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <h3 class="modal-title">角色配置</h3>
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
            </div>
            <div class="row" style="margin: 5px;">
                <div class="col-lg-8">
                    <div class="step-pane">
                        <div id="using_tree"></div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="block">
                        <a id="Btn_Save" class="btn btn-success"><i class="fa fa-floppy-o"></i>&nbsp;保存配置</a>
                        <br /><br />
                        <label>资源模块</label>
                        <input class="form-control single-line" id="SelectModule" name="SelectModule" type="text" readonly value="">
                        <input type="hidden" id="SelectModuleId" name="SelectModuleId" value="" />
                    </div>
                </div>
            </div>
            <hr />
        </div>
    </div>
</div>